'use strict';
module.exports = {
	/**
	 * 获取广场列表
	 * @url client/bbs/pub/getSquareList 前端调用的url参数地址
	 * data 请求参数
	 * @param {String} params1  参数1
	 */
	main: async (event) => {
		let { data = {}, userInfo, util, filterResponse, originalParam } = event;
		let { customUtil, uniID, config, pubFun, vk, db, _ } = util;
		let { uid, pageNo, pageSize } = data;
		let res = { code: 0, msg: "" };
		console.log(uid);
		// 业务逻辑开始-----------------------------------------------------------
		let whereJson = { bbs_status: 1 };
		//课程分类
		if (data.cid != '') whereJson["category_id"] = data.cid
		// 要关联取出 评论条数
		let dbName = "bbs_article";
		res = await vk.baseDao.selects({
			dbName,
			getMain: false, // 是否只返回rows数据
			pageIndex: pageNo, // 当前第几页
			pageSize: pageSize, // 每页条数
			whereJson,
			sortArr: [{ "name": "_add_time", "type": "desc" }],
			fieldJson: {
				content: true,
				uid: true,
				category_id: true,
				images: true,
				_add_time: true,
				like_count: true
			},
			foreignDB: [{
					dbName: "user-bbs-tumbup",
					localKey: "_id",
					foreignKey: "posts_id",
					as: "tumbups",
					fieldJson: { _id: true }
				}, {
					dbName: "user-bbs-tumbup",
					localKey: "_id",
					foreignKey: "posts_id",
					as: "tumbup",
					fieldJson: { _id: true },
					whereJson: {
						user_id: uid
					},
					limit: 1,
				}, {
					dbName: "user-bbs-star",
					localKey: "_id",
					foreignKey: "posts_id",
					as: "star",
					fieldJson: { _id: true },
					whereJson: {
						user_id: uid
					},
					limit: 1,
				}, {
					dbName: "uni-id-users",
					localKey: "uid",
					foreignKey: "_id",
					as: "user",
					fieldJson: { nickname: true, avatar: true },
					limit: 1,
				},
				{
					dbName: "bbs_category",
					localKey: "category_id",
					foreignKey: "_id",
					as: "categoey",
					fieldJson: { name: true },
					limit: 1,
				},
				{
					dbName: "bbs_comments",
					localKey: "_id",
					foreignKey: "aid",
					as: "comments",
					// limit: 5,
					foreignDB: [{
						dbName: "uni-id-users",
						localKey: "uid",
						foreignKey: "_id",
						as: "user",
						fieldJson: { nickname: true, avatar: true },
						limit: 1,
					}],
				}
			]
		});
		// 业务逻辑结束-----------------------------------------------------------
		return res;
	}
}
